using System;
using System.Collections.Generic;
using System.Text;

namespace Tetrazune
{

    public struct HighScore
    {
        public String DeviceName;
        public String Name;
        public int Score;

        public HighScore(string deviceName, string name, int score)
        {
            DeviceName = deviceName;
            Name = name;
            Score = score;
        }

        public String Pack()
        {
            return HighScore.Pack(this);
        }

        public static String Pack(HighScore score)
        {
            return score.Name + "," + score.Score.ToString();
        }

        public static HighScore Unpack(String packedHighScore)
        {
            return Unpack(packedHighScore, "local");
        }

        public static HighScore Unpack(String packedHighScore, String deviceName)
        {
            HighScore hs = new HighScore();
            String[] split = packedHighScore.Split(',');
            hs.DeviceName = deviceName;
            hs.Name = split[0];
            hs.Score = Int32.Parse(split[1]);
            return hs;
        }

        public static string Serialize(HighScore hs)
        {
            String name = hs.Name.Replace('|', ' ');
            String devName = hs.DeviceName.Replace('|', ' ');
            return devName + "|" + name + "|" + hs.Score.ToString();
        }

        public static HighScore Deserialize(String data)
        {
            HighScore hs = new HighScore();
            String[] str = data.Split(new char[] { '|' });
            hs.DeviceName = str[0];
            hs.Name = str[1];
            hs.Score = Int32.Parse(str[2]);
            return hs;
        }
    }
}